package cn.yyh.basic.controller;

import cn.yyh.basic.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

/**
 * @author 杨永航
 * @version 1.0
 * @Title: MailController
 * @Package: cn.yyh.basic.controller
 * @date 2021/6/29
 */
@RestController
@RequestMapping("/mail")
public class MailController {
    @Autowired
    private JavaMailSender javaMailSender;

    @GetMapping("register")
    public R register(@RequestParam("email") String email) {
        try {
            MimeMessage message = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true, "utf-8");
            helper.setFrom("386360678@qq.com");
            helper.setSubject("店铺入驻审核通知");
            helper.setText("<h1>恭喜您,您的店铺已经审核通过,赶快登陆看看吧!</h1>",true);
            //添加附件
           // helper.addAttachment("罗宾.jpg",new File("C:\\Users\\hasee\\Desktop\\12.webp"));
            //收件人
            helper.setTo(email);
            javaMailSender.send(message);
            return R.oK();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }
}
